#include <iostream>
#include <map>
#include <string>
using namespace std;

bool P(int num)
{
    if (num <= 1)
        return false;
    for (int i = 2; i * i <= num; ++i)
    {
        if (num % i == 0)
            return false;
    }
    return true;
}

int f(int num)
{
    int s = num - 1;
    int l = num + 1;

    while (true)
        {
        if (P(s))
        {
            return s;
        } else if (P(l))
        {
            return l;
        }
        s--;
        l++;
    }
}
int main()
{
    string words;
    string num = "";
    getline(cin, words);
    map<string, unsigned> nums_and_words;
    nums_and_words["zero"] = '0';
    nums_and_words["one"] = '1';
    nums_and_words["two"] = '2';
    nums_and_words["three"] = '3';
    nums_and_words["four"] = '4';
    nums_and_words["five"] = '5';
    nums_and_words["six"] = '6';
    nums_and_words["seven"] = '7';
    nums_and_words["eight"] = '8';
    nums_and_words["nine"] = '9';
    if(words.find(' ') != string::npos and words.rfind(' ') != string::npos)
    {
        int ind_first_space = words.find(' ');
        int ind_second_space = words.rfind(' ');
        string slovo1 = words.substr(0, ind_first_space);
        string slovo2 = words.substr(ind_first_space + 1, ind_second_space - ind_first_space - 1);
        string slovo3 = words.substr(ind_second_space + 1, words.size() - ind_second_space);
        if (slovo1=="zero" or slovo1=="one" or slovo1=="two" or slovo1=="three" or slovo1=="four" or slovo1=="five" or slovo1=="six" or slovo1=="seven" or slovo1=="eight" or slovo1=="nine")
        {
            if (slovo2=="zero" or slovo2=="one" or slovo2=="two" or slovo2=="three" or slovo2=="four" or slovo2=="five" or slovo2=="six" or slovo2=="seven" or slovo2=="eight" or slovo2=="nine")
            {
                if (slovo3=="zero" or slovo3=="one" or slovo3=="two" or slovo3=="three" or slovo3=="four" or slovo3=="five" or slovo3=="six" or slovo3=="seven" or slovo3=="eight" or slovo3=="nine")
                {
                    char slovo = nums_and_words[words.substr(0, ind_first_space)];
                    num = num + slovo;
                    slovo = nums_and_words[words.substr(ind_first_space + 1, ind_second_space - ind_first_space - 1)];
                    num = num + slovo;
                    slovo = nums_and_words[words.substr(ind_second_space + 1, words.size() - ind_second_space)];
                    num = num + slovo;
                    int int_num = stoi(num);
                    if (P(int_num))
                        cout<<int_num;
                    else
                        cout<<f(int_num);
                }
                else
                    cout<<"Wrong input";
            }
            else
                cout<<"Wrong input";
        }
        else
            cout<<"Wrong input";
    }
    else
        cout<<"Wrong input";

    return 0;
}
